package be.ipl.pigolo.testUcc;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.junit.Before;
import org.junit.Test;

import be.ipl.pigolo.usecases.GestionPartie;

public class TestCreationPartie {

	private static GestionPartie gp;

	@Before
	public void setUp() throws Exception {
		try {
			Context jndi = new InitialContext();
			gp = (GestionPartie) jndi
					.lookup("ejb:PigoloEAR/PigoloEJB/GestionPartieImpl!be.ipl.pigolo.usecases.GestionPartie");
			assertNotNull(gp);
		} catch (NamingException e) {
			e.printStackTrace();
		}

		// une partie est déjà initialiser en DB
		this.gp.creerPartie("partie5",3);
	}

	@Test
	public void testCreationPartiePartieNull() {
		assertFalse(this.gp.creerPartie("",3));
	}

	@Test
	public void testCreationPartiePartieMauvaisCaractère() {
		assertFalse(this.gp.creerPartie("$ùµù^,e",3));
	}

	@Test
	public void testCreationPartiePartieTropLongue() {
		assertFalse(this.gp.creerPartie("superPartieBienLongue",3));
	}

	@Test
	public void testCreationPartiePartieDejaInit() {
		assertFalse(this.gp.creerPartie("partie5",3));
	}

	@Test
	public void testCreationPartiePartieValide() {
		assertTrue(this.gp.creerPartie("partie6",3));
	}

}
